﻿<?php

$db = mysqli_connect('localhost', 'root' ,'123456', 'dbControlHorario');
	if(!$db) {
		// Show error if we cannot connect.
		echo 'ERROR: Could not connect to the database.';
	} else {
		// Is there a posted query string?
		if(isset($_POST['queryString'])) {
			$queryString = $_POST['queryString'];
			// Is the string length greater than 0?
			if(strlen($queryString) >0) {
				// Run the query: We use LIKE '$queryString%'
				// The percentage sign is a wild-card, in my example of countries it works like this...
				// $queryString = 'Uni';
				// Returned data = 'United States, United Kindom';
				// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
				// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
				 $query2 = mysqli_query($db,"SELECT idImagen, nombre FROM Persona  where idPersona = $queryString");
				 $query = mysqli_query($db,"SELECT P.idImagen, P.nombre, count(H.idPersona) as Nro FROM Persona P, Horario H WHERE H.idPersona=P.idPersona and H.idPersona = $queryString AND H.fecha = Curdate() GROUP BY P.nombre");
				 			
				if($query2) {
					$result = $query->fetch_object();	
					$result2 = $query2->fetch_object();	
					if($result2->idImagen !="")
					{			
					// While there are results loop through them - fetching an Object (i like PHP5 btw!).
				
						// Format the results, im using <li> for the list, you can change it.
						// The onClick function fills the textbox with the result.
						// YOU MUST CHANGE: $result->value to $result->your_colum
						
						if($result->Nro !="")
						{
						echo "<p style='text-align:left; color:#ffffff; border-bottom:solid 1px #FFFFFF; margin:3px 0px 5px 0px; padding:3px 0px 3px 0px'><b>Buenas Noches $result->nombre !!!</b></p>";
						echo "<img src='imagen_mostrar?id=$result2->idImagen' width='90' height='120'>";	         			
						}
						else{
						echo "<p style='text-align:left; color:#ffffff; border-bottom:solid 1px #FFFFFF; margin:3px 0px 5px 0px; padding:3px 0px 3px 0px'><b>Buen Dia $result2->nombre !!!</b></p>";
						echo "<img src='imagen_mostrar?id=$result2->idImagen' width='90' height='120'>";
						}
	         		}					
					else
					{
						echo "<img src='Imagenes/Image.jpg' width='90' height='120' />";
						         			
					}
				} 
				else {
						echo "Codigo Invalido";	
						echo "<img src='Imagenes/Image.jpg' width='90' height='120' />";
				}
			} else {
				// Dont do anything.
			} // There is a queryString.
		} else {
			
		}
	}
?>